package com.war.demo;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 设置过滤器
 */
@Configuration
public class WebAppConfig extends WebMvcConfigurerAdapter {

    /**
     * 解决拦截器TokenInterceptor中无法注入实例bean的问题
     * 在WebAppConfig实例时springbean还没有创建 无法注入bean 所以在这直接实例bean
     *
     * @param
     */
//    @Bean
//    public TokenInterceptor getTokenInterceptor() {
//
//        return new TokenInterceptor();
//    }
//
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
////        对所有的进行拦截  "/**"   放行登录页面"/user/login"
////         TokenInterceptor 内使用@Autowired注解引入bean实例，必然导致无法注入，实例为null的情况。
//        registry.addInterceptor(getTokenInterceptor()).addPathPatterns("/**")
//                .excludePathPatterns("/user/login")//不校验登录
//                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**")//对swagger2的拦截设置
//                .excludePathPatterns("/user/register")//不校验注册
//                .excludePathPatterns("/downloadFile/**");
//    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //swagger增加url映射
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
